<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Syncme</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
<script type="text/javascript" src="js/jquery-1.9.0.min.js"></script>
<script type="text/javascript" src="js/jquery.validate.js"></script>
<script type="text/javascript" src="js/bootstrap.js"></script>
<!-- inclusao do css -->

<style type="text/css">
textarea {  /* position is inherited */
    left: 0; 
    top: 0; 
    right: 0;
    bottom: 100px;  /* Actually the height of select and input */
    width: 100%;
}
html,body,form,#main { height:92%; }
.mainInput { height:100%; resize:none;}
</style>
</head>
<body>
<button class="signout btn">Sign Out</button>
<button class="gettext btn">Get Text</button>
<button class="updatetext btn">Update Text</button>
<div class="well" id="main">
<form id="target">
<input type="hidden" id="opt" name="opt" value="UPDATE_TEXT">
<input type="hidden" id="id" name="id" value="0">
<textarea class="mainInput" id="text" name="text"></textarea>
</form>
</div>

<script type="text/javascript">

var ScreenController = {
		module:"syncme",
		listener:"ProfileListener.php",
		
		init:function(){
	
			

		},
		
		checkLogin:function(){
			$.ajax({
				type:"POST",
				dataType:"json",
				url:ScreenController.module+"/"+ScreenController.listener,
				data:"opt=CHECK_LOGIN", 
				success: function(response) {
					if(response.error!=0  && response.error!=undefined){
						alert(response.msgError);
						window.location = "index.html";
						
					}
					
				}
			});
		},
		
		getText:function(){
			$.ajax({
				type:"POST",
				dataType:"json",
				url:ScreenController.module+"/"+ScreenController.listener,
				data:"opt=GET_TEXT", 
				success: function(response) {
					
					if(response.error!=0  && response.error!=undefined){
						alert(response.msgError);
						window.location = "index.html";
						
					}else{
						$("#text").val(response.text);
						$("#id").val(response.id);
						
					}
				}
			});
		},
		
		updateText:function(){
			$.ajax({
				type:"POST",
				dataType:"json",
				url:ScreenController.module+"/"+ScreenController.listener,
				data:$('#target').serialize(), 
				success: function(response) {
					
					if(response.error!=0  && response.error!=undefined){
						alert(response.msgError);
					}else{
						alert(response.msg);
					}
				}
			});
		}
};

ScreenController.init();

$(function(){
	ScreenController.getText();
	
	$(".signout").click(function(){
		
		$.ajax({
			type:"POST",
			dataType:"json",
			url:ScreenController.module+"/"+ScreenController.listener,
			data:"opt=LOGOUT", 
			success: function(response) {
				window.location = "index.html";
			}
		});
	});
	
$(".gettext").click(function(){
		
	ScreenController.getText();
	
	});
	
$(".updatetext").click(function(){
		
	ScreenController.updateText();
	
	});
	
	
	
	$( "#target" ).submit(function( event ) {
		event.preventDefault();
		});

});
	
</script>
</body>
</html>